package com.shenmazong.servereduresume.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.shenmazong.servereduresume.dto.TbProject;
import com.shenmazong.servereduresume.dto.TbSkillInformation;
import com.shenmazong.servereduresume.dto.TbWork;
import com.shenmazong.servereduresume.mapper.TbWorkMapper;
import com.shenmazong.servereduresume.service.TbWorkService;
import com.shenmazong.utils.ResultResponse;
import com.shenmazong.vo.BatchChooseIdVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 *
 */
@Service
public class TbWorkServiceImpl extends ServiceImpl<TbWorkMapper, TbWork>
implements TbWorkService {
    @Autowired
    private TbWorkMapper tbWorkMapper;
    @Override
    public ResultResponse findByInformationId(BatchChooseIdVo batchChooseIdVo) {
        Object o = batchChooseIdVo.getParamMap().get("informationId");
        if (o==null){
            return ResultResponse.FAILED("非法参数");
        }
        List<TbWork> one = null;
        try {
            one = tbWorkMapper.selectList(new QueryWrapper<TbWork>().lambda().eq(TbWork::getInformationId, o)
            .eq(TbWork::getDeleteFlag,0));
        } catch (Exception e) {
            e.printStackTrace();
            return ResultResponse.FAILED();
        }
        return ResultResponse.SUCCESS(one);
    }

    @Override
    public ResultResponse saveOrUpdateWork(TbWork tbWork) {
        try {
            if (tbWork.getWorkId()==null) {
                tbWorkMapper.insert(tbWork);
            }else {
                tbWorkMapper.updateById(tbWork);
            }
        } catch (Exception e) {
            e.printStackTrace();
            return ResultResponse.FAILED();
        }
        return ResultResponse.SUCCESS();
    }

    @Override
    public ResultResponse deleteWork(BatchChooseIdVo batchChooseIdVo) {
        if (batchChooseIdVo.getIds().size()==0){
            return ResultResponse.FAILED("至少选择一个删除");
        }
        try {
            for (Long id : batchChooseIdVo.getIds()) {
                TbWork certificate = tbWorkMapper.selectById(id);
                certificate.setDeleteFlag((byte) 1);
                tbWorkMapper.updateById(certificate);
            }
        } catch (Exception e) {
            e.printStackTrace();
            return ResultResponse.FAILED();
        }
        return ResultResponse.SUCCESS();
    }
}




